package com.rmb.common.model.sensitive;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

/**
 * @version 1.0
 * @Author ZhaoMuYang
 * @Date 2021/1/16 21:46
 */
public class NameUtil {

    private static final int ONE = 1;
    private static final int FIVE = 5;
    private static final int SIX = 6;
    /**
     * 密码类型枚举
     * @author ASUS
     */
    public enum TYPE {
        /**
         * 字符型
         */
        LETTER,
        /**
         * 大写字符型
         */
        CAPITAL,
        /**
         * 数字型
         */
        NUMBER,
        /**
         * 符号型
         */
        SIGN,
        /**
         * 大+小字符 型
         */
        LETTER_CAPITAL,
        /**
         * 小字符+数字 型
         */
        LETTER_NUMBER,
        /**
         * 大+小字符+数字 型
         */
        LETTER_CAPITAL_NUMBER,
        /**
         * 大+小字符+数字+符号 型
         */
        LETTER_CAPITAL_NUMBER_SIGN
    }

    private static final String[] LOWERCASE = {
            "a","b","c","d","e","f","g","h","i","j","k",
            "l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};

    private static final String[] CAPITAL = {
            "A","B","C","D","E","F","G","H","I","J","K",
            "L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};

    private static final String[] NUMBER = {
            "1","2","3","4","5","6","7","8","9","0"};

    private static final String[] SIGN = {
            "~","!","@","#","$","%","^","&","*","(",")","_","+","`","-","=",
            "{","}","|",":","\"","<",">","?",
            "[","]","\\",";","'",",",".","/"};

    /**
     * 静态随机数
     */
    private static final Random RANDOM = new Random();


    public static String ruleengineJava(){
        return NameUtil.getRandom(ONE,TYPE.CAPITAL)+NameUtil.getRandom(FIVE,TYPE.LETTER)
                +NameUtil.getRandom(ONE,TYPE.CAPITAL)+NameUtil.getRandom(FIVE,TYPE.LETTER);
    }
    public static String ruleengineSql(){
        return NameUtil.getRandom(ONE,TYPE.CAPITAL)+NameUtil.getRandom(FIVE,TYPE.LETTER)
                +NameUtil.getRandom(SIX,TYPE.NUMBER);
    }

    /**
     * 获取随机组合码
     * 字符型 LETTER,
     * 大写字符型 CAPITAL,
     * 数字型 NUMBER,
     * 符号型 SIGN,
     * 大+小字符型 LETTER_CAPITAL,
     * 小字符+数字 型 LETTER_NUMBER,
     * 大+小字符+数字 型 LETTER_CAPITAL_NUMBER,
     * 大+小字符+数字+符号 型 LETTER_CAPITAL_NUMBER_SIGN
     * @param num 位数
     * @param type 类型
     */
    public static String getRandom(int num,TYPE type){
        ArrayList<String> temp = new ArrayList<>();
        StringBuffer code = new StringBuffer();
        if(type == TYPE.LETTER){
            temp.addAll(Arrays.asList(LOWERCASE));
        }else if(type == TYPE.CAPITAL){
            temp.addAll(Arrays.asList(CAPITAL));
        }else if(type == TYPE.NUMBER){
            temp.addAll(Arrays.asList(NUMBER));
        }else if(type == TYPE.SIGN){
            temp.addAll(Arrays.asList(SIGN));
        }else if(type == TYPE.LETTER_CAPITAL){
            temp.addAll(Arrays.asList(LOWERCASE));
            temp.addAll(Arrays.asList(CAPITAL));
        }else if(type == TYPE.LETTER_NUMBER){
            temp.addAll(Arrays.asList(LOWERCASE));
            temp.addAll(Arrays.asList(NUMBER));
        }else if(type == TYPE.LETTER_CAPITAL_NUMBER){
            temp.addAll(Arrays.asList(LOWERCASE));
            temp.addAll(Arrays.asList(CAPITAL));
            temp.addAll(Arrays.asList(NUMBER));
        }else if(type == TYPE.LETTER_CAPITAL_NUMBER_SIGN){
            temp.addAll(Arrays.asList(LOWERCASE));
            temp.addAll(Arrays.asList(CAPITAL));
            temp.addAll(Arrays.asList(NUMBER));
            temp.addAll(Arrays.asList(SIGN));
        }
        for (int i = 0; i < num; i++) {
            code.append(temp.get(RANDOM.nextInt(temp.size())));
        }
        return code.toString();
    }

}
